home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / src / tcl / tclAPI.c next >
Encoding:
C/C++ Source or Header  |  1994-07-20  |  27.1 KB  |  1,105 lines

  1. /* $Id: tclAPI.c,v 1.5 1994/07/19 22:33:05 mjl Exp $
  2.  * $Log: tclAPI.c,v $
  3.  * Revision 1.5  1994/07/19  22:33:05  mjl
  4.  * Internal header file inclusion changed to /not/ use a search path so that
  5.  * it will work better with makedepend.
  6.  *
  7.  * Revision 1.4  1994/06/30  18:52:09  mjl
  8.  * Added API calls for: plfont, plfontld, plhist, pljoin, plmtex, plptex,
  9.  * plschr, plssub, plsym, plvpor, plwid.
  10.  *
  11.  * Revision 1.3  1994/06/25  20:37:12  mjl
  12.  * Added API calls for pladv, plbop, plbox, pleop, plstyl, plvsta, plwind.
  13.  *
  14.  * Revision 1.2  1994/06/24  20:38:21  mjl
  15.  * Changed name of struct to tclMatrix to avoid conflicts with C++ Matrix
  16.  * classes.
  17.  *
  18.  * Revision 1.1  1994/06/23  22:45:50  mjl
  19.  * Contains functions, a command table, a hash table, and other tools to
  20.  * support calling PLplot functions via Tcl commands.  Support for calling
  21.  * PLplot directly (from pltcl) or by widget commands (from plframe) is
  22.  * provided.
  23.  */
  24.  
  25. /*----------------------------------------------------------------------*\
  26.  * 
  27.  * pltclAPI.c --
  28.  *
  29.  *    This module implements a Tcl command set for interpretively
  30.  *    calling PLplot functions.  Each Tcl command is responsible for
  31.  *    calling the appropriate underlying function in the C API.  Can be
  32.  *    used with any driver, in principle. 
  33.  *
  34.  * Maurice LeBrun
  35.  * IFS, University of Texas at Austin
  36.  * 19-Jun-1994
  37.  *
  38. \*----------------------------------------------------------------------*/
  39.  
  40. #include "plplotP.h"
  41. #include "pltcl.h"
  42.  
  43. /* PLplot/Tcl API handlers.  Prototypes must come before Cmds struct */
  44.  
  45. static int pladvCmd    (ClientData, Tcl_Interp *, int, char **);
  46. static int plbopCmd    (ClientData, Tcl_Interp *, int, char **);
  47. static int plboxCmd    (ClientData, Tcl_Interp *, int, char **);
  48. static int plcol0Cmd    (ClientData, Tcl_Interp *, int, char **);
  49. static int pleopCmd    (ClientData, Tcl_Interp *, int, char **);
  50. static int plenvCmd    (ClientData, Tcl_Interp *, int, char **);
  51. static int plfontCmd    (ClientData, Tcl_Interp *, int, char **);
  52. static int plfontldCmd    (ClientData, Tcl_Interp *, int, char **);
  53. static int plgraCmd    (ClientData, Tcl_Interp *, int, char **);
  54. static int plhistCmd    (ClientData, Tcl_Interp *, int, char **);
  55. static int pljoinCmd    (ClientData, Tcl_Interp *, int, char **);
  56. static int pllabCmd    (ClientData, Tcl_Interp *, int, char **);
  57. static int pllineCmd    (ClientData, Tcl_Interp *, int, char **);
  58. static int plmtexCmd    (ClientData, Tcl_Interp *, int, char **);
  59. static int plpoinCmd    (ClientData, Tcl_Interp *, int, char **);
  60. static int plptexCmd    (ClientData, Tcl_Interp *, int, char **);
  61. static int plschrCmd    (ClientData, Tcl_Interp *, int, char **);
  62. static int plsetoptCmd    (ClientData, Tcl_Interp *, int, char **);
  63. static int plssubCmd    (ClientData, Tcl_Interp *, int, char **);
  64. static int plsymCmd    (ClientData, Tcl_Interp *, int, char **);
  65. static int plstylCmd    (ClientData, Tcl_Interp *, int, char **);
  66. static int plsxaxCmd    (ClientData, Tcl_Interp *, int, char **);
  67. static int plsyaxCmd    (ClientData, Tcl_Interp *, int, char **);
  68. static int pltextCmd    (ClientData, Tcl_Interp *, int, char **);
  69. static int plvporCmd    (ClientData, Tcl_Interp *, int, char **);
  70. static int plvstaCmd    (ClientData, Tcl_Interp *, int, char **);
  71. static int plwidCmd    (ClientData, Tcl_Interp *, int, char **);
  72. static int plwindCmd    (ClientData, Tcl_Interp *, int, char **);
  73.  
  74. /*
  75.  * The following structure defines all of the commands in the PLplot/Tcl
  76.  * core, and the C procedures that execute them.
  77.  */
  78.  
  79. typedef struct Command {
  80.     int (*proc)();        /* Procedure to process command. */
  81.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  82.     int *deleteProc;        /* Procedure to invoke when deleting
  83.                  * command. */
  84.     ClientData deleteData;    /* Arbitrary value to pass to deleteProc
  85.                  * (usually the same as clientData). */
  86. } Command;
  87.  
  88. typedef struct {
  89.     char *name;
  90.     int (*proc)();
  91. } CmdInfo;
  92.  
  93. /* Built-in commands, and the procedures associated with them */
  94.  
  95. static CmdInfo Cmds[] = {
  96.     {"pladv",        pladvCmd},
  97.     {"plbop",        plbopCmd},
  98.     {"plbox",        plboxCmd},
  99.     {"plcol",        plcol0Cmd},
  100.     {"plcol0",        plcol0Cmd},
  101.     {"pleop",        pleopCmd},
  102.     {"plenv",        plenvCmd},
  103.     {"plfont",        plfontCmd},
  104.     {"plfontld",    plfontldCmd},
  105.     {"plgra",        plgraCmd},
  106.     {"plhist",        plhistCmd},
  107.     {"pljoin",        pljoinCmd},
  108.     {"pllab",        pllabCmd},
  109.     {"plline",        pllineCmd},
  110.     {"plmtex",        plmtexCmd},
  111.     {"plpoin",        plpoinCmd},
  112.     {"plptex",        plptexCmd},
  113.     {"plschr",        plschrCmd},
  114.     {"plssub",        plssubCmd},
  115.     {"plstyl",        plstylCmd},
  116.     {"plsxax",        plsxaxCmd},
  117.     {"plsyax",        plsyaxCmd},
  118.     {"plsetopt",    plsetoptCmd},
  119.     {"plsym",        plsymCmd},
  120.     {"pltext",        pltextCmd},
  121.     {"plvpor",        plvporCmd},
  122.     {"plvsta",        plvstaCmd},
  123.     {"plwid",        plwidCmd},
  124.     {"plwind",        plwindCmd},
  125.     {NULL,        NULL}
  126. };
  127.  
  128. /* Hash table and associated flag for directing control */
  129.  
  130. static int cmdTable_initted;
  131. static Tcl_HashTable cmdTable;
  132.  
  133. /*----------------------------------------------------------------------*\
  134.  * Append_Cmdlist
  135.  *
  136.  * Generates command list from Cmds, storing into interp->result.
  137. \*----------------------------------------------------------------------*/
  138.  
  139. static void
  140. Append_Cmdlist(Tcl_Interp *interp)
  141. {
  142.     register CmdInfo *cmdInfoPtr;
  143.     for (cmdInfoPtr = Cmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) {
  144.     Tcl_AppendResult(interp, cmdInfoPtr->name, (char *) NULL);
  145.     }
  146. }
  147.  
  148. /*----------------------------------------------------------------------*\
  149.  * plTclCmd_Init
  150.  *
  151.  * Sets up command hash table for use with plframe to PLplot Tcl API.
  152.  *
  153.  * Right now all API calls are allowed, although some of these may not
  154.  * make much sense when used with a widget.
  155. \*----------------------------------------------------------------------*/
  156.  
  157. static void
  158. plTclCmd_Init(Tcl_Interp *interp)
  159. {
  160.     register Command *cmdPtr;
  161.     register CmdInfo *cmdInfoPtr;
  162.  
  163.     Tcl_InitHashTable(&cmdTable, TCL_STRING_KEYS);
  164.  
  165. /* Create the hash table entry for each command */
  166.  
  167.     for (cmdInfoPtr = Cmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) {
  168.     int new;
  169.     Tcl_HashEntry *hPtr;
  170.  
  171.     hPtr = Tcl_CreateHashEntry(&cmdTable, cmdInfoPtr->name, &new);
  172.     if (new) {
  173.         cmdPtr = (Command *) ckalloc(sizeof(Command));
  174.         cmdPtr->proc = cmdInfoPtr->proc;
  175.         cmdPtr->clientData = (ClientData) NULL;
  176.         cmdPtr->deleteProc = NULL;
  177.         cmdPtr->deleteData = (ClientData) NULL;
  178.         Tcl_SetHashValue(hPtr, cmdPtr);
  179.     }
  180.     }
  181. }
  182.  
  183. /*----------------------------------------------------------------------*\
  184.  * plTclCmd
  185.  *
  186.  * Front-end to PLplot/Tcl API for use from Tcl commands (e.g. plframe).
  187.  *
  188.  * This command is called by the plframe widget to process subcommands
  189.  * of the "cmd" plframe widget command.  This is the plframe's direct
  190.  * plotting interface to the PLplot library.  This routine can be called
  191.  * from other commands that want a similar capability.
  192.  *
  193.  * In a widget-based application, a plplot "command" doesn't make much
  194.  * sense by itself since it isn't connected to a specific widget.
  195.  * Instead, you have widget commands.  This allows arbitrarily many
  196.  * widgets and requires a slightly different syntax than if there were
  197.  * only a single output device.  That is, the widget name (and in this
  198.  * case, the "cmd" widget command, after that comes the subcommand)
  199.  * must come first.  The plframe widget checks first for one of its
  200.  * internal subcommands, those specifically designed for use with the
  201.  * plframe widget.  If not found, control comes here. 
  202. \*----------------------------------------------------------------------*/
  203.  
  204. int
  205. plTclCmd(char *cmdlist, Tcl_Interp *interp, int argc, char **argv)
  206. {
  207.     register Tcl_HashEntry *hPtr;
  208.     int result = TCL_OK;
  209.  
  210. /* Create hash table on first call */
  211.  
  212.     if ( ! cmdTable_initted) {
  213.     cmdTable_initted = 1;
  214.     plTclCmd_Init(interp);
  215.     }
  216.  
  217. /* no option -- return list of available PLPlot commands */
  218.  
  219.     if (argc == 0) {
  220.     Tcl_AppendResult(interp, cmdlist, (char *) NULL);
  221.     Append_Cmdlist(interp);
  222.     return TCL_OK;
  223.     }
  224.  
  225. /* Pick out the desired command */
  226.  
  227.     hPtr = Tcl_FindHashEntry(&cmdTable, argv[0]);
  228.     if (hPtr == NULL) {
  229.     Tcl_AppendResult(interp, "bad option to \"cmd\": must be one of ",
  230.              cmdlist, (char *) NULL);
  231.     Append_Cmdlist(interp);
  232.     result = TCL_ERROR;
  233.     }
  234.     else {
  235.     register Command *cmdPtr = (Command *) Tcl_GetHashValue(hPtr);
  236.     result = (*cmdPtr->proc)(cmdPtr->clientData, interp, argc, argv);
  237.     }
  238.  
  239.     return result;
  240. }
  241.  
  242. /*----------------------------------------------------------------------*\
  243.  * Pltcl_Init
  244.  *
  245.  * Initialization routine for extended wish'es.
  246.  * Creates the matrix command, as well as numerous commands for
  247.  * interfacing to PLplot.  Should not be used in a widget-based system.
  248. \*----------------------------------------------------------------------*/
  249.  
  250. int
  251. Pltcl_Init( Tcl_Interp *interp )
  252. {
  253.     register CmdInfo *cmdInfoPtr;
  254.  
  255. /* matrix -- matrix support command */
  256.  
  257.     Tcl_CreateCommand(interp, "matrix", Tcl_MatrixCmd,
  258.                       (ClientData) NULL, (void (*)(ClientData)) NULL);
  259.  
  260. /* PLplot API commands */
  261.  
  262.     for (cmdInfoPtr = Cmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) {
  263.  
  264.     Tcl_CreateCommand(interp, cmdInfoPtr->name, cmdInfoPtr->proc,
  265.               (ClientData) NULL, (void (*)(ClientData)) NULL);
  266.     }
  267.  
  268.     return TCL_OK;
  269. }
  270.  
  271. /*----------------------------------------------------------------------*\
  272.  * PLplot API Calls
  273.  *
  274.  * Any call that results in something actually being plotted must be
  275.  * followed by by a call to plflush(), to make sure all output from 
  276.  * that command is finished.  Devices that have text/graphics screens
  277.  * (e.g. Tek4xxx and emulators) implicitly switch to the graphics screen
  278.  * before graphics commands, so a plgra() is not necessary in this case.
  279.  * Although if you switch to the text screen via user control (instead of
  280.  * using pltext()), the device will get confused.
  281. \*----------------------------------------------------------------------*/
  282.  
  283. /* TEMPLATE */
  284.  
  285. /*----------------------------------------------------------------------*\
  286.  * plxxxCmd
  287.  *
  288.  * Processes plxxx Tcl command.
  289. \*----------------------------------------------------------------------*/
  290.  
  291. static int
  292. plxxxCmd(ClientData clientData, Tcl_Interp *interp,
  293.      int argc, char **argv)
  294. {
  295.     if (argc != 0 ) {
  296.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  297.              argv[0], " \"",
  298.              (char *) NULL);
  299.     return TCL_ERROR;
  300.     }
  301.  
  302.  
  303.     plflush();
  304.     return TCL_OK;
  305. }
  306.  
  307. /*----------------------------------------------------------------------*\
  308.  * pladvCmd
  309.  *
  310.  * Processes pladv Tcl command.
  311. \*----------------------------------------------------------------------*/
  312.  
  313. static int
  314. pladvCmd(ClientData clientData, Tcl_Interp *interp,
  315.      int argc, char **argv)
  316. {
  317.     int sub = 0;
  318.  
  319.     if (argc > 2 ) {
  320.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  321.              argv[0], " ?subwindow?\"",
  322.              (char *) NULL);
  323.     return TCL_ERROR;
  324.     }
  325.  
  326.     if (argc == 2) 
  327.     sub = atoi(argv[1]);
  328.  
  329.     pladv(sub);
  330.  
  331.     plflush();
  332.     return TCL_OK;
  333. }
  334.  
  335. /*----------------------------------------------------------------------*\
  336.  * plbopCmd
  337.  *
  338.  * Processes plbop Tcl command.
  339. \*----------------------------------------------------------------------*/
  340.  
  341. static int
  342. plbopCmd(ClientData clientData, Tcl_Interp *interp,
  343.      int argc, char **argv)
  344. {
  345.     if (argc > 1 ) {
  346.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  347.              argv[0], " \"",
  348.              (char *) NULL);
  349.     return TCL_ERROR;
  350.     }
  351.  
  352.     plbop();
  353.  
  354.     plflush();
  355.     return TCL_OK;
  356. }
  357.  
  358. /*----------------------------------------------------------------------*\
  359.  * plboxCmd
  360.  *
  361.  * Processes plbox Tcl command.
  362. \*----------------------------------------------------------------------*/
  363.  
  364. static int
  365. plboxCmd(ClientData clientData, Tcl_Interp *interp,
  366.      int argc, char **argv)
  367. {
  368.     char *xopt, *yopt;
  369.     PLFLT xtick, ytick;
  370.     PLINT nxsub, nysub;
  371.  
  372.     if (argc != 7 ) {
  373.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  374.              argv[0], " xopt xtick nxsub yopt ytick nysub\"",
  375.              (char *) NULL);
  376.     return TCL_ERROR;
  377.     }
  378.  
  379.     xopt = argv[1];
  380.     xtick = atof(argv[2]);
  381.     nxsub = atoi(argv[3]);
  382.  
  383.     yopt = argv[4];
  384.     ytick = atof(argv[5]);
  385.     nysub = atoi(argv[6]);
  386.  
  387.     plbox(xopt, xtick, nxsub, yopt, ytick, nysub);
  388.  
  389.     plflush();
  390.     return TCL_OK;
  391. }
  392.  
  393. /*----------------------------------------------------------------------*\
  394.  * plcol0Cmd
  395.  *
  396.  * Processes plcol0 Tcl command.
  397. \*----------------------------------------------------------------------*/
  398.  
  399. static int
  400. plcol0Cmd(ClientData clientData, Tcl_Interp *interp,
  401.       int argc, char **argv)
  402. {
  403.     PLINT col;
  404.  
  405.     if (argc != 2) {
  406.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  407.              " color-index\"",
  408.              (char *) NULL);
  409.     return TCL_ERROR;
  410.     }
  411.  
  412.     col = atoi( argv[1] );
  413.  
  414.     plcol0( col );
  415.  
  416.     return TCL_OK;
  417. }
  418.  
  419. /*----------------------------------------------------------------------*\
  420.  * plenvCmd
  421.  *
  422.  * Processes plenv Tcl command.
  423. \*----------------------------------------------------------------------*/
  424.  
  425. static int
  426. plenvCmd(ClientData clientData, Tcl_Interp *interp,
  427.      int argc, char **argv)
  428. {
  429.     PLFLT xmin, xmax, ymin, ymax;
  430.     PLINT just, axis;
  431.  
  432.     if (argc != 7 ) {
  433.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  434.              " xmin xmax ymin ymax just axis\"",
  435.              (char *) NULL);
  436.     return TCL_ERROR;
  437.     }
  438.  
  439.     xmin = atof( argv[1] );
  440.     xmax = atof( argv[2] );
  441.     ymin = atof( argv[3] );
  442.     ymax = atof( argv[4] );
  443.     just = atoi( argv[5] );
  444.     axis = atoi( argv[6] );
  445.  
  446.     plenv( xmin, xmax, ymin, ymax, just, axis );
  447.  
  448.     plflush();
  449.     return TCL_OK;
  450. }
  451.  
  452. /*----------------------------------------------------------------------*\
  453.  * pleopCmd
  454.  *
  455.  * Processes pleop Tcl command.
  456. \*----------------------------------------------------------------------*/
  457.  
  458. static int
  459. pleopCmd(ClientData clientData, Tcl_Interp *interp,
  460.      int argc, char **argv)
  461. {
  462.     if (argc > 1 ) {
  463.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  464.              argv[0], "\"",
  465.              (char *) NULL);
  466.     return TCL_ERROR;
  467.     }
  468.  
  469.     pleop();
  470.  
  471.     plflush();
  472.     return TCL_OK;
  473. }
  474.  
  475. /*----------------------------------------------------------------------*\
  476.  * plfontCmd
  477.  *
  478.  * Processes plfont Tcl command.
  479. \*----------------------------------------------------------------------*/
  480.  
  481. static int
  482. plfontCmd(ClientData clientData, Tcl_Interp *interp,
  483.       int argc, char **argv)
  484. {
  485.     PLINT font;
  486.  
  487.     if (argc != 2 ) {
  488.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  489.              argv[0], " font\"",
  490.              (char *) NULL);
  491.     return TCL_ERROR;
  492.     }
  493.  
  494.     font = atoi(argv[1]);
  495.  
  496.     plfont(font);
  497.  
  498.     return TCL_OK;
  499. }
  500.  
  501. /*----------------------------------------------------------------------*\
  502.  * plfontldCmd
  503.  *
  504.  * Processes plfontld Tcl command.
  505. \*----------------------------------------------------------------------*/
  506.  
  507. static int
  508. plfontldCmd(ClientData clientData, Tcl_Interp *interp,
  509.         int argc, char **argv)
  510. {
  511.     PLINT font;
  512.  
  513.     if (argc != 2 ) {
  514.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  515.              argv[0], " font\"",
  516.              (char *) NULL);
  517.     return TCL_ERROR;
  518.     }
  519.  
  520.     font = atoi(argv[1]);
  521.  
  522.     plfontld(font);
  523.  
  524.     return TCL_OK;
  525. }
  526.  
  527. /*----------------------------------------------------------------------*\
  528.  * plgraCmd
  529.  *
  530.  * Processes plgra Tcl command.
  531. \*----------------------------------------------------------------------*/
  532.  
  533. static int
  534. plgraCmd(ClientData clientData, Tcl_Interp *interp,
  535.      int argc, char **argv)
  536. {
  537.     if (argc > 1 ) {
  538.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  539.              argv[0], " \"",
  540.              (char *) NULL);
  541.     return TCL_ERROR;
  542.     }
  543.  
  544.     plgra();
  545.  
  546.     return TCL_OK;
  547. }
  548.  
  549. /*----------------------------------------------------------------------*\
  550.  * plhistCmd
  551.  *
  552.  * Processes plhist Tcl command.
  553. \*----------------------------------------------------------------------*/
  554.  
  555. static int
  556. plhistCmd(ClientData clientData, Tcl_Interp *interp,
  557.       int argc, char **argv)
  558. {
  559.     PLINT n, nbin, oldwin;
  560.     PLFLT *data, datmin, datmax;
  561.     tclMatrix *mat;
  562.  
  563.     if (argc != 7 ) {
  564.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  565.              argv[0], " n data datmin datmax nbin oldwin\"",
  566.              (char *) NULL);
  567.     return TCL_ERROR;
  568.     }
  569.  
  570.     n = atoi(argv[1]);
  571.     mat = Tcl_GetMatrixPtr(interp, argv[2]);
  572.     data = mat->fdata;
  573.     datmin = atof( argv[3] );
  574.     datmax = atof( argv[4] );
  575.     nbin = atoi( argv[5] );
  576.     oldwin = atoi( argv[6] );
  577.  
  578.     plhist(n, data, datmin, datmax, nbin, oldwin);
  579.  
  580.     plflush();
  581.     return TCL_OK;
  582. }
  583.  
  584. /*----------------------------------------------------------------------*\
  585.  * pljoinCmd
  586.  *
  587.  * Processes pljoin Tcl command.
  588. \*----------------------------------------------------------------------*/
  589.  
  590. static int
  591. pljoinCmd(ClientData clientData, Tcl_Interp *interp,
  592.       int argc, char **argv)
  593. {
  594.     PLFLT x1, y1, x2, y2;
  595.  
  596.     if (argc != 5 ) {
  597.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  598.              argv[0], " x1 y1 x2 y2\"",
  599.              (char *) NULL);
  600.     return TCL_ERROR;
  601.     }
  602.  
  603.     x1 = atof( argv[1] );
  604.     y1 = atof( argv[2] );
  605.     x2 = atof( argv[3] );
  606.     y2 = atof( argv[4] );
  607.  
  608.     pljoin(x1, y1, x2, y2);
  609.  
  610.     plflush();
  611.     return TCL_OK;
  612. }
  613.  
  614. /*----------------------------------------------------------------------*\
  615.  * pllabCmd
  616.  *
  617.  * Processes pllab Tcl command.
  618. \*----------------------------------------------------------------------*/
  619.  
  620. static int
  621. pllabCmd(ClientData clientData, Tcl_Interp *interp,
  622.       int argc, char **argv)
  623. {
  624.     if (argc != 4 ) {
  625.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  626.              argv[0], " xlabel ylabel tlabel\"",
  627.              (char *) NULL);
  628.     return TCL_ERROR;
  629.     }
  630.  
  631.     pllab( argv[1], argv[2], argv[3] );
  632.  
  633.     plflush();
  634.     return TCL_OK;
  635. }
  636.  
  637. /*----------------------------------------------------------------------*\
  638.  * pllineCmd
  639.  *
  640.  * Processes plline Tcl command.
  641. \*----------------------------------------------------------------------*/
  642.  
  643. static int
  644. pllineCmd(ClientData clientData, Tcl_Interp *interp,
  645.        int argc, char **argv)
  646. {
  647.     PLFLT *x, *y;
  648.     tclMatrix *matx, *maty;
  649.     int n;
  650.  
  651.     if (argc != 4 ) {
  652.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  653.              " n x-array y-array\"",
  654.              (char *) NULL);
  655.     return TCL_ERROR;
  656.     }
  657.  
  658.     matx = Tcl_GetMatrixPtr(interp, argv[2]);
  659.     x = matx->fdata;
  660.     maty = Tcl_GetMatrixPtr(interp, argv[3]);
  661.     y = maty->fdata;
  662.  
  663.     if (strncmp(argv[1], "*", 1) == 0)
  664.     n = MIN(matx->len, maty->len);
  665.     else
  666.     n = atoi(argv[1]);
  667.  
  668.     plline( n, x, y );
  669.  
  670.     plflush();
  671.     return TCL_OK;
  672. }
  673.  
  674. /*----------------------------------------------------------------------*\
  675.  * plmtexCmd
  676.  *
  677.  * Processes plmtex Tcl command.
  678. \*----------------------------------------------------------------------*/
  679.  
  680. static int
  681. plmtexCmd(ClientData clientData, Tcl_Interp *interp,
  682.       int argc, char **argv)
  683. {
  684.     char *side, *text;
  685.     PLFLT disp, pos, just;
  686.  
  687.     if (argc != 6 ) {
  688.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  689.              argv[0], " side disp pos just text\"",
  690.              (char *) NULL);
  691.     return TCL_ERROR;
  692.     }
  693.  
  694.     side = argv[1];
  695.     disp = atof(argv[2]);
  696.     pos = atof(argv[3]);
  697.     just = atof(argv[4]);
  698.     text = argv[5];
  699.  
  700.     plmtex(side, disp, pos, just, text);
  701.  
  702.     plflush();
  703.     return TCL_OK;
  704. }
  705.  
  706. /*----------------------------------------------------------------------*\
  707.  * plpoinCmd
  708.  *
  709.  * Processes plpoin Tcl command.
  710. \*----------------------------------------------------------------------*/
  711.  
  712. static int
  713. plpoinCmd(ClientData clientData, Tcl_Interp *interp,
  714.        int argc, char **argv)
  715. {
  716.     PLFLT *x, *y;
  717.     tclMatrix *matx, *maty;
  718.     int n, code;
  719.  
  720.     if (argc != 5 ) {
  721.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  722.              " n x-array y-array code\"",
  723.              (char *) NULL);
  724.     return TCL_ERROR;
  725.     }
  726.  
  727.     matx = Tcl_GetMatrixPtr(interp, argv[2]);
  728.     x = matx->fdata;
  729.     maty = Tcl_GetMatrixPtr(interp, argv[3]);
  730.     y = maty->fdata;
  731.     code = atoi( argv[4] );
  732.  
  733.     if (strncmp(argv[1], "*", 1) == 0)
  734.     n = MIN(matx->len, maty->len);
  735.     else
  736.     n = atoi(argv[1]);
  737.  
  738.     plpoin( n, x, y, code );
  739.  
  740.     plflush();
  741.     return TCL_OK;
  742. }
  743.  
  744. /*----------------------------------------------------------------------*\
  745.  * plptexCmd
  746.  *
  747.  * Processes plptex Tcl command.
  748. \*----------------------------------------------------------------------*/
  749.  
  750. static int
  751. plptexCmd(ClientData clientData, Tcl_Interp *interp,
  752.       int argc, char **argv)
  753. {
  754.     PLFLT x, y, dx, dy, just;
  755.     char *text;
  756.  
  757.     if (argc != 7 ) {
  758.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  759.              argv[0], " x y dx dy just text\"",
  760.              (char *) NULL);
  761.     return TCL_ERROR;
  762.     }
  763.  
  764.     x = atof(argv[1]);
  765.     y = atof(argv[2]);
  766.     dx = atof(argv[3]);
  767.     dy = atof(argv[4]);
  768.     just = atof(argv[5]);
  769.     text = argv[6];
  770.  
  771.     plptex(x, y, dx, dy, just, text);
  772.  
  773.     plflush();
  774.     return TCL_OK;
  775. }
  776.  
  777. /*----------------------------------------------------------------------*\
  778.  * plschrCmd
  779.  *
  780.  * Processes plschr Tcl command.
  781. \*----------------------------------------------------------------------*/
  782.  
  783. static int
  784. plschrCmd(ClientData clientData, Tcl_Interp *interp,
  785.       int argc, char **argv)
  786. {
  787.     PLFLT def, scale;
  788.  
  789.     if (argc != 3 ) {
  790.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  791.              argv[0], " def scale\"",
  792.              (char *) NULL);
  793.     return TCL_ERROR;
  794.     }
  795.  
  796.     def = atof(argv[1]);
  797.     scale = atof(argv[2]);
  798.  
  799.     plschr(def, scale);
  800.  
  801.     return TCL_OK;
  802. }
  803.  
  804. /*----------------------------------------------------------------------*\
  805.  * plsetoptCmd
  806.  *
  807.  * Processes plsetopt Tcl command.
  808.  * Just calls plSetInternalOpt() 
  809. \*----------------------------------------------------------------------*/
  810.  
  811. static int
  812. plsetoptCmd(ClientData clientData, Tcl_Interp *interp,
  813.          int argc, char **argv)
  814. {
  815.     if (argc < 2 || argc > 3) {
  816.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  817.              argv[0], " option ?argument?\"", (char *) NULL);
  818.     return TCL_ERROR;
  819.     }
  820.  
  821.     plSetInternalOpt(argv[1], argv[2]);
  822.  
  823.     plflush();
  824.     return TCL_OK;
  825. }
  826.  
  827. /*----------------------------------------------------------------------*\
  828.  * plssubCmd
  829.  *
  830.  * Processes plssub Tcl command.
  831. \*----------------------------------------------------------------------*/
  832.  
  833. static int
  834. plssubCmd(ClientData clientData, Tcl_Interp *interp,
  835.       int argc, char **argv)
  836. {
  837.     PLINT nsubx, nsuby;
  838.  
  839.     if (argc != 3 ) {
  840.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  841.              argv[0], " nsubx nsuby\"",
  842.              (char *) NULL);
  843.     return TCL_ERROR;
  844.     }
  845.  
  846.     nsubx = atoi(argv[1]);
  847.     nsuby = atoi(argv[2]);
  848.  
  849.     plssub(nsubx, nsuby);
  850.  
  851.     plflush();
  852.     return TCL_OK;
  853. }
  854.  
  855. /*----------------------------------------------------------------------*\
  856.  * plstylCmd
  857.  *
  858.  * Processes plstyl Tcl command.
  859. \*----------------------------------------------------------------------*/
  860.  
  861. static int
  862. plstylCmd(ClientData clientData, Tcl_Interp *interp,
  863.      int argc, char **argv)
  864. {
  865.     PLINT *space, *mark, nels;
  866.     tclMatrix *mat1, *mat2;
  867.  
  868.     if (argc != 4 ) {
  869.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  870.              argv[0], " nels mark-array space-array\"",
  871.              (char *) NULL);
  872.     return TCL_ERROR;
  873.     }
  874.  
  875.     nels = atoi(argv[1]);
  876.     mat1 = Tcl_GetMatrixPtr(interp, argv[2]);
  877.     space = mat1->idata;
  878.     mat2 = Tcl_GetMatrixPtr(interp, argv[3]);
  879.     mark = mat2->idata;
  880.  
  881.     plstyl(nels, mark, space);
  882.  
  883.     return TCL_OK;
  884. }
  885.  
  886. /*----------------------------------------------------------------------*\
  887.  * plsxaxCmd
  888.  *
  889.  * Processes plsxax Tcl command.
  890. \*----------------------------------------------------------------------*/
  891.  
  892. static int
  893. plsxaxCmd(ClientData clientData, Tcl_Interp *interp,
  894.       int argc, char **argv)
  895. {
  896.     PLINT digmax;
  897.  
  898.     if (argc < 1 ) {
  899.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  900.              argv[0], " digmax\"",
  901.              (char *) NULL);
  902.     return TCL_ERROR;
  903.     }
  904.  
  905.     digmax = atoi(argv[1]);
  906.  
  907.     plsxax(digmax, 0);
  908.  
  909.     return TCL_OK;
  910. }
  911.  
  912. /*----------------------------------------------------------------------*\
  913.  * plsyaxCmd
  914.  *
  915.  * Processes plsyax Tcl command.
  916. \*----------------------------------------------------------------------*/
  917.  
  918. static int
  919. plsyaxCmd(ClientData clientData, Tcl_Interp *interp,
  920.       int argc, char **argv)
  921. {
  922.     PLINT digmax;
  923.  
  924.     if (argc < 1 ) {
  925.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  926.              argv[0], " digmax\"",
  927.              (char *) NULL);
  928.     return TCL_ERROR;
  929.     }
  930.  
  931.     digmax = atoi(argv[1]);
  932.  
  933.     plsyax(digmax, 0);
  934.  
  935.     return TCL_OK;
  936. }
  937.  
  938. /*----------------------------------------------------------------------*\
  939.  * plsymCmd
  940.  *
  941.  * Processes plsym Tcl command.
  942. \*----------------------------------------------------------------------*/
  943.  
  944. static int
  945. plsymCmd(ClientData clientData, Tcl_Interp *interp,
  946.      int argc, char **argv)
  947. {
  948.     PLFLT *x, *y;
  949.     tclMatrix *matx, *maty;
  950.     int n, code;
  951.  
  952.     if (argc != 5 ) {
  953.     Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
  954.              " n x-array y-array code\"",
  955.              (char *) NULL);
  956.     return TCL_ERROR;
  957.     }
  958.  
  959.     matx = Tcl_GetMatrixPtr(interp, argv[2]);
  960.     x = matx->fdata;
  961.     maty = Tcl_GetMatrixPtr(interp, argv[3]);
  962.     y = maty->fdata;
  963.     code = atoi( argv[4] );
  964.  
  965.     if (strncmp(argv[1], "*", 1) == 0)
  966.     n = MIN(matx->len, maty->len);
  967.     else
  968.     n = atoi(argv[1]);
  969.  
  970.     plsym( n, x, y, code );
  971.  
  972.     plflush();
  973.     return TCL_OK;
  974. }
  975.  
  976. /*----------------------------------------------------------------------*\
  977.  * pltextCmd
  978.  *
  979.  * Processes pltext Tcl command.
  980. \*----------------------------------------------------------------------*/
  981.  
  982. static int
  983. pltextCmd(ClientData clientData, Tcl_Interp *interp,
  984.       int argc, char **argv)
  985. {
  986.     if (argc > 1 ) {
  987.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  988.              argv[0], " \"",
  989.              (char *) NULL);
  990.     return TCL_ERROR;
  991.     }
  992.  
  993.     pltext();
  994.  
  995.     return TCL_OK;
  996. }
  997.  
  998. /*----------------------------------------------------------------------*\
  999.  * plvporCmd
  1000.  *
  1001.  * Processes plvpor Tcl command.
  1002. \*----------------------------------------------------------------------*/
  1003.  
  1004. static int
  1005. plvporCmd(ClientData clientData, Tcl_Interp *interp,
  1006.       int argc, char **argv)
  1007. {
  1008.     PLFLT xmin, xmax, ymin, ymax;
  1009.  
  1010.     if (argc != 5 ) {
  1011.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  1012.              argv[0], " xmin xmax ymin ymax\"",
  1013.              (char *) NULL);
  1014.     return TCL_ERROR;
  1015.     }
  1016.  
  1017.     xmin = atof( argv[1] );
  1018.     xmax = atof( argv[2] );
  1019.     ymin = atof( argv[3] );
  1020.     ymax = atof( argv[4] );
  1021.  
  1022.     plvpor(xmin, xmax, ymin, ymax);
  1023.  
  1024.     return TCL_OK;
  1025. }
  1026.  
  1027. /*----------------------------------------------------------------------*\
  1028.  * plvstaCmd
  1029.  *
  1030.  * Processes plvsta Tcl command.
  1031. \*----------------------------------------------------------------------*/
  1032.  
  1033. static int
  1034. plvstaCmd(ClientData clientData, Tcl_Interp *interp,
  1035.       int argc, char **argv)
  1036. {
  1037.     if (argc > 1 ) {
  1038.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  1039.              argv[0], " \"",
  1040.              (char *) NULL);
  1041.     return TCL_ERROR;
  1042.     }
  1043.  
  1044.     plvsta();
  1045.  
  1046.     return TCL_OK;
  1047. }
  1048.  
  1049. /*----------------------------------------------------------------------*\
  1050.  * plwidCmd
  1051.  *
  1052.  * Processes plwid Tcl command.
  1053. \*----------------------------------------------------------------------*/
  1054.  
  1055. static int
  1056. plwidCmd(ClientData clientData, Tcl_Interp *interp,
  1057.      int argc, char **argv)
  1058. {
  1059.     PLINT width;
  1060.  
  1061.     if (argc != 2 ) {
  1062.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  1063.              argv[0], " width\"",
  1064.              (char *) NULL);
  1065.     return TCL_ERROR;
  1066.     }
  1067.  
  1068.     width = atoi(argv[1]);
  1069.  
  1070.     plwid(width);
  1071.  
  1072.     return TCL_OK;
  1073. }
  1074.  
  1075. /*----------------------------------------------------------------------*\
  1076.  * plwindCmd
  1077.  *
  1078.  * Processes plwind Tcl command.
  1079. \*----------------------------------------------------------------------*/
  1080.  
  1081. static int
  1082. plwindCmd(ClientData clientData, Tcl_Interp *interp,
  1083.       int argc, char **argv)
  1084. {
  1085.     PLFLT xmin, xmax, ymin, ymax;
  1086.  
  1087.     if (argc != 5 ) {
  1088.     Tcl_AppendResult(interp, "wrong # args: should be \"",
  1089.              argv[0], " xmin xmax ymin ymax\"",
  1090.              (char *) NULL);
  1091.     return TCL_ERROR;
  1092.     }
  1093.  
  1094.     xmin = atof(argv[1]);
  1095.     xmax = atof(argv[2]);
  1096.     ymin = atof(argv[3]);
  1097.     ymax = atof(argv[4]);
  1098.  
  1099.     plwind(xmin, xmax, ymin, ymax);
  1100.  
  1101.     plflush();
  1102.     return TCL_OK;
  1103. }
  1104.  
  1105.